# api.employee.py 員工管理接口封裝

# 導包
import requests
import app


# 創建接口類
class EmployeeAPI:
    # 創建接口
    # 初始化
    def __init__(self):
        self.url_add_employee = app.BASE_URL + "/api/sys/user"
        self.url_update_employee = app.BASE_URL + "/api/sys/user/{}" # 用{}代表佔位符號,之後用format還原
        self.url_get_employee = app.BASE_URL + "/api/sys/user/{}" # 用{}代表佔位符號,之後用format還原
        self.url_delete_employee = app.BASE_URL + "/api/sys/user/{}" # 用{}代表佔位符號,之後用format還原

    # 新增員工
    def add_employee(self, add_employee_data):
        return requests.post(url=self.url_add_employee, json=add_employee_data, headers=app.headers_data)

    # 修改員工
    def update_employee(self, employee_id, update_employee_data):
        url = self.url_update_employee.format(employee_id)
        return requests.put(url=url, json=update_employee_data, headers=app.headers_data)

    # 查詢員工
    def get_employee(self, employee_id):
        url = self.url_get_employee.format(employee_id)
        return requests.get(url=url, headers=app.headers_data)

    # 刪除員工
    def delete_employee(self, employee_id):
        url = self.url_delete_employee.format(employee_id)
        return requests.delete(url=url, headers=app.headers_data)
